package com.apimarket.controller;

import com.apimarket.entity.SysRole;
import com.apimarket.entity.vo.JsonResult;
import com.apimarket.service.SysRoleService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.rpc.ServiceException;

@RequestMapping("/role/")
@RestController
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;

    @RequestMapping("doFindPageObjects")
    public JsonResult doFindPageObjects(String name, Integer page,
                                        Integer pageSize) throws ServiceException {
        return new JsonResult(
                sysRoleService.findPageObject(name, page,pageSize)
        );
    }

    @RequestMapping("doDeleteObject")
    public JsonResult doDeleteObject(Integer id) throws ServiceException {
        sysRoleService.deleteObject(id);
        return new JsonResult("delete ok");
    }

    @RequestMapping("doSaveObject")
    public JsonResult doSaveObject(SysRole entity, Integer[] menuIds) throws ServiceException {
        sysRoleService.saveObject(entity, menuIds);
        return new JsonResult("save ok");
    }

    @RequestMapping("testA")
    public JsonResult testA(SysRole entity) {
        return new JsonResult("controllerA" + entity.getName());
    }

    @RequestMapping("testB")
    public JsonResult testB(Integer[] menuIds) {
        return new JsonResult("controllerB" + menuIds);
    }

    //修改操作，把之前的数据先返回过来
    @RequestMapping("doFindObjectById")
    public JsonResult doFindObjectById(Integer id) throws ServiceException {
        return new JsonResult(sysRoleService.findObjectById(id));
    }

    @RequestMapping("doUpdateObject")
    public JsonResult doUpdateObject(SysRole entity,
                                     Integer[] menuIds) throws ServiceException {
        sysRoleService.updateObject(entity, menuIds);
        return new JsonResult("update ok");
    }

    @RequestMapping("doFindRoles")
    public JsonResult doFindRoles(Integer page, Integer pageSize) {
        return new JsonResult(sysRoleService.findObjects(page,pageSize));
    }


}